package br.com.linkers.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import br.com.linkers.enums.Operadoras;
import br.com.linkers.enums.Tipos;

@Entity
@Table(name = "telefones")
public class Telefones implements Serializable {

	private static final long serialVersionUID = -2944340263407757869L;

	@Id
	@Column(name = "telefone_id")
	@SequenceGenerator(name = "seq_telefone", sequenceName = "seq_telefone", allocationSize = 1)
	@GeneratedValue(generator = "seq_telefone", strategy = GenerationType.SEQUENCE)
	private Long id;

	@Column(length = 3, columnDefinition = "char(3)")
	private String ddd;

	@Column(length = 10, columnDefinition = "char(10)")
	private String numero;

	// Relacoes com enums
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "operadora_enum", length = 1, columnDefinition = "Integer")
	private Operadoras operadora;

	@Enumerated(EnumType.ORDINAL)
	@Column(name = "tipo_enum", length = 1, columnDefinition = "Integer")
	private Tipos tipo;

	// Relacao com outras tabelas
	@ManyToOne
	@JoinColumn(name = "fk_usuario_id", referencedColumnName = "usuario_id")
	private Usuarios usuario;

	@ManyToMany
	@JoinTable(name = "telefone_grupo", joinColumns = @JoinColumn(name = "telefone_id"), inverseJoinColumns = @JoinColumn(name = "grupo_id"))
	private List<Grupos> grupo;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDdd() {
		return ddd;
	}

	public void setDdd(String ddd) {
		this.ddd = ddd;
	}

	public String getNumero() {
		return numero;
	}

	public void setNumero(String numero) {
		this.numero = numero;
	}

	public Operadoras getOperadora() {
		return operadora;
	}

	public void setOperadora(Operadoras operadora) {
		this.operadora = operadora;
	}

	public Tipos getTipo() {
		return tipo;
	}

	public void setTipo(Tipos tipo) {
		this.tipo = tipo;
	}

	public Usuarios getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuarios usuario) {
		this.usuario = usuario;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Telefones other = (Telefones) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Telefones [id=" + id + ", ddd=" + ddd + ", numero=" + numero
				+ ", operadora=" + operadora + ", tipo=" + tipo + ", usuario="
				+ usuario + "]";
	}

	// gets and sets

}